package com.base.cn.platform.os.controller.mobile.agent.income;

import com.base.cn.platform.os.common.MobileBaseController;
import com.base.cn.platform.os.common.utils.ObjectUtils;
import com.base.cn.platform.os.service.course.agent.user.AgentUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.Map;

/**
 * 推广员总收益Controller
 * @author LIZHIPENG
 * @create 2018-06-29 下午 3:24
 */
@Controller
@RequestMapping("/mobile/uc/agent/income")
public class MobileAgentIncomeController extends MobileBaseController {

    @Autowired
    private AgentUserService agentUserService;

    /**
     * 查询推广员总收益
     * @param model Model
     * @param request HttpServletRequest
     * @return String
     */
    @RequestMapping("/initAgentIncomeView")
    public String initAgentIncomeView(Model model, HttpServletRequest request){
        BigDecimal userId = webMobileLoginUtil.getLoginUserId(request);
        Map<String, Object> agentUser = agentUserService.findAgentUserByUserId(userId, true, false, true);
        if(ObjectUtils.isNotEmpty(agentUser)){
            model.addAttribute("agentUser", agentUser);
            return resultPage("/agent/income/agent-income");
        }else {
            return redirect(request, "/mobile/uc/agent/toOpenExtensionView");
        }
    }
}
